package cn.frh.order.controller;


import cn.frh.basic.util.AjaxResult;
import cn.frh.basic.util.LoginContext;
import cn.frh.basic.util.PageList;
import cn.frh.order.domain.AdoptOrder;
import cn.frh.order.domain.ProductOrder;
import cn.frh.order.query.AdoptOrderQuery;
import cn.frh.order.query.ProductOrderQuery;
import cn.frh.order.service.IProductOrderService;
import cn.frh.product.domain.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/productOrder")
public class ProductOrderController {

    @Autowired
    private IProductOrderService productOrderService;
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){
        try{
            //payData 支付信息
            String payData = productOrderService.submit(params, LoginContext.getCurrentLogininfo(request));
            System.out.println(payData);
            return AjaxResult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("下单失败！"+e.getMessage());
        }
    }
    //1.后台查询接口 领养订单
    @PostMapping("/admin")
    public PageList<ProductOrder> admin(@RequestBody ProductOrderQuery query, HttpServletRequest request){
        return productOrderService.admin(query,LoginContext.getCurrentLogininfo(request));
    }
}
